package com.chap1;

/**
 * <p>
 * <code>NoUseJoin</code>
 * </p>
 *
 * @author junbao3
 * TODO
 * @date 2023-03-23 14:41
 * Copyright (C) 2021 IFlyTek. All rights reserved.
 */
public class NoUseJoin {
    static  class Goddess implements Runnable{
        private Thread thread;

        public Goddess(Thread thread) {
            this.thread = thread;
        }

        public Goddess() {
        }

        @Override
        public void run() {
            System.out.println("女神开始排队打饭...");
            if (thread!=null){
                try {
                    thread.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(Thread.currentThread().getName()+"  女神打饭完成");
        }
    }

    static class GoddessBoyfriend implements Runnable{

        @Override
        public void run() {
            System.out.println("女神男友开始排队打饭");
            System.out.println(Thread.currentThread().getName()+" 女神男友打饭完成");
        }
    }
    public static void main(String[] args) {
        Thread zhangsan = Thread.currentThread();

        Thread goddessBoyfriend = new Thread(new GoddessBoyfriend());

        Thread goddess = new Thread(new Goddess());
        goddessBoyfriend.start();
        goddess.start();
        System.out.println("张三开始排队打饭...");
        System.out.println(zhangsan.getName()+" 张三打饭完成");
    }
}
